home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Original Code / Menus / ContextMenuAdd / ContextMenuAdd.cs next >
Encoding:
Text File  |  2001-01-15  |  1.4 KB  |  50 lines

  1. //---------------------------------------------
  2. // ContextMenuAdd.cs ⌐ 2001 by Charles Petzold
  3. //---------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class ContextMenuAdd: Form
  9. {
  10.      MenuItem miColor;
  11.  
  12.      public static void Main()
  13.      {
  14.           Application.Run(new ContextMenuAdd());
  15.      }
  16.      public ContextMenuAdd()
  17.      {
  18.           Text = "Context Menu Using Add";
  19.  
  20.           ContextMenu  cm = new ContextMenu();
  21.           EventHandler eh = new EventHandler(MenuColorOnClick);
  22.  
  23.           cm.MenuItems.Add("Black",   eh);
  24.           cm.MenuItems.Add("Blue",    eh);
  25.           cm.MenuItems.Add("Green",   eh);
  26.           cm.MenuItems.Add("Cyan",    eh);
  27.           cm.MenuItems.Add("Red",     eh);
  28.           cm.MenuItems.Add("Magenta", eh);
  29.           cm.MenuItems.Add("Yellow",  eh);
  30.           cm.MenuItems.Add("White",   eh);
  31.  
  32.           foreach (MenuItem mi in cm.MenuItems)
  33.                mi.RadioCheck = true;
  34.  
  35.           miColor = cm.MenuItems[3];
  36.           miColor.Checked = true;
  37.           BackColor = Color.FromName(miColor.Text);
  38.  
  39.           ContextMenu = cm;
  40.      }
  41.      void MenuColorOnClick(object obj, EventArgs ea)
  42.      {
  43.           miColor.Checked = false;
  44.           miColor = (MenuItem) obj;
  45.           miColor.Checked = true;
  46.  
  47.           BackColor = Color.FromName(miColor.Text);
  48.      }
  49. }
  50.